<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<%@ include file="/commons/head.jsp" %>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <%@ include file="/commons/left.jsp" %>
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                文章列表
            </h1>
            <section class="content">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box">
                            <div class="box-header">
                                <form  name="searchForm" id="searchForm"
                                       action="${ctx}/article/listArticle" method="get">
                                    <input type="hidden" id="pageNum" name="pageNum" value="1" />
                                    <input type="hidden" id="length" name="length" value="10" />
                                    <label style=" float: left; height: 34px; line-height: 34px;">文章状态：</label>
                                    <div class="input" style="float: left;" >
                                        <select name="articleStatus"  class="form-control">
                                            <option value="1"
                                                    <c:if test="${query.articleStatus==1}">selected="selected"</c:if>>发布</option>
                                            <option value="0"
                                                    <c:if test="${query.articleStatus==0}">selected="selected"</c:if>>未发布</option>
                                        </select>
                                    </div>
                                    <div class="input_btn" style=" float: left;">
                                        <input type="submit" class="btn btn-default" value="查询">
                                    </div>
                                </form>
                                <div class="margin" style="float:right;">
                                    <button type="button" class="btn btn-default" onclick="window.location.href='${ctx}/article/editSysArticle?action=add&id='"><span
                                            class="glyphicon glyphicon-plus" ></span> 新增
                                    </button>
                                </div>
                            </div>
                            <div class="box-body">
                                <table id="example2" class="table table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <th>文章标题</th>
                                        <th>文章号</th>
                                        <th>浏览次数</th>
                                        <th>作者</th>
                                        <th>文章来源</th>
                                        <th>文章简介</th>
                                        <th>页面描述</th>
                                        <th>推荐位置</th>
                                        <th>关键词</th>
                                        <th>文章分类</th>
                                        <th>操作人</th>
                                        <th class="time">创建时间</th>
                                        <th>文章状态</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:if test="${page.maxRow > 0}">
                                        <c:forEach var="item" items="${listArticle}" varStatus="vs">
                                            <tr>
                                                <td>${item.title}</td>
                                                <td>${item.articleId}</td>
                                                <td>${item.browseTimes}</td>
                                                <td>${item.auther}</td>
                                                <td>${item.fileFrom}</td>
                                                <td>${item.abstracts}</td>
                                                <td>${item.describes}</td>
                                                <td>
                                                    <c:if test="${item.articleOrder == 0}">
                                                        首页显示
                                                    </c:if>
                                                    <c:if test="${item.articleOrder == 1}">
                                                        列表显示
                                                    </c:if>
                                                </td>
                                                <td>${item.keyword}</td>
                                                <td>${item.categoryId}</td>
                                                <td>${item.operator}</td>
                                                <td><fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${item.createTime}"></fmt:formatDate></td>
                                                <c:if test="${item.articleStatus==0}">
                                                    <td><span class="red">未发布</span></td>
                                                    <td><a onclick="if (confirm('您确定要启用吗？'))enable('${item.id}',1)"
                                                           data-able="1">启用</a><em></em><a
                                                            onclick="window.location.href='${ctx}/article/editSysArticle?action=update&id=${item.id}'">修改</a><em></em><a
                                                            onclick="if (confirm('您确定要删除吗？')) deleteArticle('${item.id}')">删除</a></td>
                                                </c:if>
                                                <c:if test="${item.articleStatus==1}">
                                                    <td><span class="green">发布</span></td>
                                                    <td><a onclick="if (confirm('您确定要禁用吗？'))enable('${item.id}',0)"
                                                           data-able="0">禁用</a><em></em><a onclick="window.location.href='${ctx}/article/editSysArticle?action=update&id=${item.id}'">修改</a><em></em><a
                                                            onclick="if (confirm('您确定要删除吗？')) deleteArticle('${item.id}')">删除</a></td>
                                                </c:if>
                                                </td>
                                            </tr>
                                        </c:forEach>
                                    </c:if>
                                    </tbody>
                                </table>
                                <div>
                                    <jsp:include page="/commons/pagination.jsp"/>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </section>

    </div>
    <%@ include file="/commons/script.jsp" %>
</body>
<script type="text/javascript">
    function deleteArticle(id) {
        $.ajax({
            cache: false,
            type: "post",
            url: "${ctx}/article/deleteSysArticle",
            data: {id: id},
            error: function () {
                alert("系统异常");
            },
            success: function (data) {
                if (data == 1) {
                    alert("删除成功");
                } else {
                    alert("删除失败");
                }
                location.reload()
            }
        });
    }
    //更改状态
    function enable(id,obj){
        //ajax
        $.ajax({
            cache: false,
            type: "post",
            url: "${ctx}/article/updaterArticleStatus?",
            data: {
                id:id,
                articleStatus:obj
            },
            success: function(data) {
                if(data == 1){
                    //成功处理
                    if(obj == 0){
                        alert("禁用成功");
                    }else{
                        alert("启用成功");
                    }
                    location.reload()
                }
            },
            error: function() {
                alert("系统异常");
            }
        });
    }
</script>
</html>



